
import string
from decimal import Decimal as D

zf = lambda x, y: string.zfill(str(x), y)
sf = lambda x, y: x + ((y - len(x)) * ' ')

def hhmmss_sec(t):
    ''' convert time to seconds
        hh:mm:ss -> (hh*60*60)+(mm*60)+ss
    '''
    r = (int(t[:2])*60*60) # hh
    r += (int(t[3:5])*60) # mm
    r += int(t[6:]) # ss
    return r
    
if 0:
    print hhmmss_sec('00:02:20'), 140
    print hhmmss_sec('00:02:00'), 120
    print hhmmss_sec('00:01:20'), 80
    print hhmmss_sec('00:10:20'), 620
    print hhmmss_sec('00:30:00'), 1800

def pace_distance(pace_500m, target_time):
    ''' input   pace per 500m, target time (minutes)
        output  distance (m)
    '''
    print '%s/500m' % pace_500m, 
    print ' (%s : target time)' % (target_time, ), 
    #m_s = 500/(hhmmss_sec(pace))
    #m_s = 500/D(hhmmss_sec(pace))
    m_s = 500/float(hhmmss_sec(pace_500m))
    distance = hhmmss_sec(target_time) * m_s

    print ' (%s : m/s)' % (sf(str(m_s), 13), ), 
    print ' (%s : distance)' % (sf(str(distance), 13))
    return distance

if __name__ == "__main__":

    if 1:
        pace_distance('00:01:58', '00:30:00')
        pace_distance('00:01:59', '00:30:00')
        pace_distance('00:02:00', '00:30:00')
        pace_distance('00:02:01', '00:30:00')
        pace_distance('00:02:02', '00:30:00')
        pace_distance('00:02:03', '00:30:00')
        pace_distance('00:02:04', '00:30:00')
        pace_distance('00:02:05', '00:30:00')
        pace_distance('00:02:06', '00:30:00')
        pace_distance('00:02:07', '00:30:00')
        pace_distance('00:02:08', '00:30:00')
        pace_distance('00:02:09', '00:30:00')
        pace_distance('00:02:10', '00:30:00')
        
        pace_distance('00:02:00', '00:10:00')


